home *** CD-ROM | disk | FTP | other *** search
Text File | 1989-06-26 | 3.8 KB | 115 lines | [TEXT/GEOL] |
- Item 5893594 18-May-89 13:29
-
- From: STONECUTTER Stonecutter SW, Don Sawtelle, PRT
-
- To: D0420 Satori SW, Hugh Rogovy, PRT
-
- cc: MACDTS Macintosh Developer Technical Supt.
- MACAPP.TECH$ MACAPP Tech
-
- Sub: view hierarchy --> 'view' rsrc
-
- To: D0420, MACDTS, MACAPP.TECH$
- In response to: "How to use WriteRes????" From Chris Le Croy, Satori Software
-
- Chris writes:
-
- >> Does anyone know how to use the WriteRes methods? I haven't been able to
- >> find it documented anywhere, except for very brief mentions
-
- Chris,
-
- At the end of this message I've included an edited excerpt of code which may be
- helpful as an example of how to save a view hierarchy as a resource.
-
- This example saves the view hierarchies contained by each of a document's
- windows as 'view' resources in the resource fork of a document file. This works
- because I call IDocument with the kUsesRsrcFork and kRsrcOpen flags. Perhaps
- there are hidden pitfalls in doing that--but it's worked so far for me.
-
- Please don't expect it to be more than an example. I quickly edited out code
- which is not relevant, and have not tested it since. It may contain old bugs,
- new bugs, reflect my ignorance, horrible errors in judgement, etc., etc.
-
- Also, it is specific to our project. For instance, it saves only the view
- hierarchy in the window--not the window itself--and assumes that each window
- contains exactly one subview (though that view may contain any number of
- subviews itself, ad infinitum.)
-
- You may wish to write a more general version which tests whether the window has
- any subviews, and works no matter how many there are. It'd be great if you
- would post a description of your experiences (and example source) back to
- MacApp.Tech$.
-
- If anyone in MacApp.Tech$ or MacDTS knows more about this or can point out
- errors or add additional information, _please post a note to MacApp.Tech$
- Perhaps the current programmers of ViewEdit would like to comment? Surely you
- guys are the most knowledgeable on this topic.
-
- Hope this helps,
-
- Don Sawtelle
- Applelink: Stonecutter
- (415) 851-5665
-
- Stonecutter Software (contract Mac software development/consulting)
- 47 Skylonda Drive
- Woodside, CA 94062-3721
-
- {---------------------------------------------------------------------------}
- PROCEDURE TMyDocument.DoWrite(aRefNum: INTEGER; makingCopy: BOOLEAN); OVERRIDE;
- VAR
- theWindow: TWindow;
- aHandle: ViewRsrcHndl;
- p: Ptr;
- rsrcNumber: Integer;
-
- PROCEDURE SaveSubview( theView: TView );
- BEGIN
- IF (theView <> NIL) THEN
- BEGIN
- theView.WriteRes( aHandle, p );
- IF theView.CountSubViews > 0 THEN
- theView.fSubviews.Each( SaveSubview );
- END
- END;
-
- PROCEDURE SaveWindowContents( theWindow: TWindow );
- VAR
- singleSubView: TView;
- aStr255: Str255;
- BEGIN
- { Warning: this code assumes the window contains a single subview }
- { of type TScreen (which can in turn contain subviews of any type.) }
- { Your app may need this changed so that it works when a window contains
- }
- { any number (0 to n) of subviews. }
-
- singleSubView := TView( theWindow.fSubViews.First );
-
- aHandle := NewViewRsrc( p );
- singleSubView.WriteRes( aHandle, p );
-
- IF singleSubView.CountSubViews > 0 THEN
- singleSubView.fSubviews.Each( SaveSubview );
-
- DoneViewRsrc( aHandle, p );
-
- AddResource( Handle(aHandle), 'view', rsrcNumber, 'Test!' );
- WriteResource( Handle(aHandle) );
- FailOSErr(ResError);
-
- rsrcNumber := rsrcNumber + 1;
- END;
-
- {.............................................................}
- BEGIN
- Inherited DoWrite(aRefNum, makingCopy);
-
- rsrcNumber := 1;
- self.fWindowList.Each( SaveWindowContents );
- END;
-
-
-
-